﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sportsbook.Domain.Models.Lines;
using Sportsbook.Domain.Repositories;
using Sportsbook.InMemoryPersistence.Models.Lines;

namespace Sportsbook.InMemoryPersistence.Repositories
{
    public class LinesRepository : ILinesRepository
    {
        private IEnumerable<Line> GetList()
        {
            var random = new Random();
            var trends = Enum.GetValues(typeof(Trend));

            var lines = new List<Line>
                {                  
                    new Line
                    {
                        EventId =  Guid.NewGuid().ToString(),
                        SportId = "soccer",
                        MarketId = "live",
                        LeagueId = "la-liga",
                        Period = Period.FirstHalf,
                        HomeTeam = "Real Madrid",
                        AwayTeam = "Barcelona",
                        Moneyline = new Moneyline
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend = (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend = (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Handicap = 1.5m
                                        },
                        Spread = new Spread
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend = (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 1.5m
                                        },                                 
                        Total = new Total
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 2
                                        }
                    },
                    new Line
                    {
                        EventId =  Guid.NewGuid().ToString(),
                        SportId = "soccer",
                        MarketId = "live",
                        LeagueId = "la-liga",
                        Period = Period.FirstHalf,
                        HomeTeam = "Real Madrid",
                        AwayTeam = "Barcelona",
                        Moneyline = new Moneyline
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Handicap = 1.5m
                                        },
                        Spread = new Spread
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 1.5m
                                        },             
                        Total = new Total
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 2
                                        } 
                    },
                    new Line
                    {
                        EventId =  Guid.NewGuid().ToString(),
                        SportId = "soccer",
                        MarketId = "live",
                        LeagueId = "la-liga",
                        Period = Period.FirstHalf,
                        HomeTeam = "Real Madrid",
                        AwayTeam = "Barcelona",
                        Moneyline = new Moneyline
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Handicap = 1.5m
                                        },
                        Spread = new Spread
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 1.5m
                                        },             
                        Total = new Total
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 2
                                        } 
                    },
                    new Line
                    {
                        EventId =  Guid.NewGuid().ToString(),
                        SportId = "soccer",
                        MarketId = "live",
                        LeagueId = "la-liga",
                        Period = Period.FirstHalf,
                        HomeTeam = "Real Madrid",
                        AwayTeam = "Barcelona",
                        Moneyline = new Moneyline
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Handicap = 1.5m
                                        },
                        Spread = new Spread
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 1.5m
                                        },             
                        Total = new Total
                                        {
                                            HomePrice = random.Next(-199,199),
                                            AwayPrice = random.Next(-199,199),
                                            HomePriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            AwayPriceTrend= (Trend)trends.GetValue(random.Next(trends.Length * random.Next(0,2))),
                                            Points = 2
                                        } 
                    }
            };

            lines[0].SportId = "soccer";
            lines[0].MarketId = "live";
            lines[0].LeagueId = "la-liga";

            lines[1].SportId = "soccer";
            lines[1].MarketId = "early-market";
            lines[1].LeagueId = "la-liga";

            lines[2].SportId = "soccer";
            lines[2].MarketId = "live";
            lines[2].LeagueId = "champions-league";

            return lines;
        }

        public List<ILine> Get(string sportId, string filterType, string leagueId)
        {
            return GetList().Cast<ILine>().ToList();
        }
        public List<ILine> Get()
        {
            return GetList().Cast<ILine>().ToList();
        }
        public void Save(ILine line)
        {
            throw new NotImplementedException();
        }
    }
}